80A - Panoramix's Prediction - CodeForces Solution


brute force *800

Please click on ads to support us..

Python Code:

prime = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227]
num,num2 = list(map(int,input().split()))
for i in range(50):
    if prime[i] == num:
        break
if prime[i+1] == num2:
    print("YES")
else:
    print("NO")
    

C++ Code:

// Problem: A. Panoramix's Prediction
// Contest: Codeforces - Codeforces Beta Round #69 (Div. 2 Only)
// URL: https://codeforces.com/problemset/problem/80/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)


#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mod 1e9 + 7
// #define for(a, c) for (int(a) = 0; (a) < (c); (a)++)
// #define forl(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
// #define forr(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define MP make_pair

void prime(vi &vec)
{
    for(int i=2;i<=50;i++)
{
	int flag=1;
for(int j=2;j<i;j++)
{
	if(i%j==0)
	{
		flag=0;
		break;
	}
}
if(flag)
vec.pb(i);
}
}

void solve()
{
	
	int n,m;
	cin>>n>>m;
    vi vec;
	prime(vec);
	int cnt=0;
	for(int i=0;i<=n;i++)
	{ 
	    if(vec[i]==n && vec[i+1]==m)
	    {
			cnt=1;
			break;
		}
	}
	if(cnt)
	{
	    cout<<"YES"<<endl;
	}
	else{
	    cout<<"NO"<<endl;
	}
}

int32_t main()
{
	solve();
}

 


Comments

Submit
0 Comments
More Questions

1302. Deepest Leaves Sum
1209. Remove All Adjacent Duplicates in String II
994. Rotting Oranges
983. Minimum Cost For Tickets
973. K Closest Points to Origin
969. Pancake Sorting
967. Numbers With Same Consecutive Differences
957. Prison Cells After N Days
946. Validate Stack Sequences
921. Minimum Add to Make Parentheses Valid
881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST